/**
 * 
 */
package ua.kiev.ntukpi.asu.ga;

import java.awt.Color;
import java.util.Random;

/**
 * @author Alexander Galibey
 *
 */
public class Utils {

	public static boolean playAction(double probability){
		
		Random random = new Random();
		double rndDouble = random.nextDouble();
		if(rndDouble > probability){
			
			return false;
		}else{
			
			return true;
		}
	}
	
	public static Color generateColor(Double fitness){
		
		if (fitness.isInfinite()){
			
			return new Color(0, 255, 0);
		}
		//double delta = (fitness - average)/fitness;
		int rgb = 100*(int)(Math.log(fitness));
		int abs = Math.abs(rgb);
		if (abs > 255){
			
			abs = 255;
		}else if(abs == 0){
			
			abs = 255;
		}
		if (rgb < 0){
			
			return new Color(abs, 0, 0);
		}else{
			return new Color(0, abs, 0);
		}
	}
	
	
}
